# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html



'''
class XinlangPipeline(object):
    def process_item(self, item, spider):
        with open(r'F:/pycharmProjects/project_scrapy/xinlang/name_xw.txt','a') as fp:
            fp.write('name:'+item['name']+'link:'+item['link']+'\n')
'''

import pymysql
class XinlangPipeline(object):

    def __init__(self):
        self.conn=pymysql.connect(host='localhost',user='root',passwd='123456',db='xw_xinlang')



    def process_item(self,item,spider):
        data1 = item['name']
        data2 = item['link']
        ###########
        sql='insert into hah(num,name,link) VALUES("%d","%s","%s")'%(0,data1,data2)
        ###########
        self.conn.query(sql)
        self.conn.commit()
        return item

    def close_spider(self,spider):
        self.conn.close()

